home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / libraries / mui20dev.lha / MUI / Developer / C / Examples / MUI-Exchange.c < prev    next >
C/C++ Source or Header  |  1994-02-11  |  20KB  |  828 lines

  1.  
  2.   /**********************************************\
  3.   *                                              *
  4.   *  MUI-Exchange                                *
  5.   *                                              *
  6.   *  Version: 0.8 (13.8.93)                      *
  7.   *                                              *
  8.   *  Copyright 1993 by kMel, Klaus Melchior      *
  9.   *  kmel@eifel.adsp.sub.org, 2:242/7.2@Fidonet  *
  10.   *                                              *
  11.   *                                              *
  12.   *  This isn't a proper replacement             *
  13.   *  for the "Exchange" from Commodore,          *
  14.   *  because it can't use the CX-Command         *
  15.   *  'CXCMD_LIST_CHG'.                           *
  16.   *                                              *
  17.   *  All these broker functions are private      *
  18.   *  and rarely documented.                      *
  19.   *                                              *
  20.   \**********************************************/
  21.  
  22.  
  23. /* DMAKE */
  24.  
  25. /* TAB=4 */
  26.  
  27.  
  28.  
  29.  
  30. /*** escape sequences ***/
  31.  
  32. #define eR "\033r"
  33. #define eC "\033c"
  34. #define eL "\033l"
  35.  
  36. #define eN "\033n"
  37. #define eB "\033b"
  38. #define eI "\033i"
  39.  
  40. #define ePB "\0332"
  41. #define ePW "\0338"
  42.  
  43.  
  44.  
  45.  
  46. /*** includes ***/
  47.  
  48. #include "demo.h"
  49.  
  50. #include <exec/memory.h>
  51. #include <libraries/commodities.h>
  52. #include <clib/commodities_protos.h>
  53.  
  54. #ifdef __SASC
  55. #include <pragmas/commodities_pragmas.h>
  56. #endif
  57.  
  58.  
  59.  
  60.  
  61. /*** private structures & defines ***/
  62.  
  63. struct BrokerCopy    {
  64.     struct Node    bc_Node;
  65.     char    bc_Name[CBD_NAMELEN];
  66.     char    bc_Title[CBD_TITLELEN];
  67.     char    bc_Descr[CBD_DESCRLEN];
  68.     LONG    bc_Task;
  69.     LONG    bc_Dummy1;
  70.     LONG    bc_Dummy2;
  71.     UWORD    bc_Flags;
  72. };
  73.  
  74. #define COF_ACTIVE 2
  75.  
  76.  
  77.  
  78.  
  79. /*** private functions of "commodities.library" ***/
  80.  
  81. #pragma libcall CxBase FindBroker 6c 801
  82. #pragma libcall CxBase CopyBrokerList ba 801
  83. #pragma libcall CxBase FreeBrokerList c0 801
  84. #pragma libcall CxBase BrokerCommand c6 802
  85.  
  86. CxObj *FindBroker(char *);
  87. LONG CopyBrokerList(struct List *);
  88. LONG FreeBrokerList(struct List *);
  89. LONG BrokerCommand(char *, LONG id);
  90.  
  91.  
  92.  
  93. /*** ids ***/
  94.  
  95. enum ids {
  96.     ID_DUMMY,
  97.     ID_ABOUT,
  98.     ID_INFO,
  99.     ID_LV_ACTIVE,
  100.     ID_ACTIVATE, ID_DEACTIVATE, ID_REMOVE,
  101.     ID_INTERFACE, ID_SHOW, ID_HIDE,
  102.     ID_QUIT,
  103. };
  104.  
  105.  
  106.  
  107.  
  108. /*** variables ***/
  109.  
  110. static APTR app;
  111. static APTR wi_main;
  112. static APTR bt_info;
  113. static APTR lv_broker;
  114. static APTR bt_activate, bt_deactivate, bt_remove;
  115. static APTR bt_show, bt_hide;
  116.  
  117. struct Library *CxBase;
  118.  
  119.  
  120.  
  121.  
  122. /*** funcs ***/
  123.  
  124. /*** find name in broker list ***/
  125.  
  126. LONG find_broker_name(char *n)
  127. {
  128.     struct BrokerCopy *bc;
  129.     LONG i;
  130.  
  131.     for (i=0; ; i++)
  132.     {
  133.         DoMethod(lv_broker, MUIM_List_GetEntry, i, &bc);
  134.  
  135.         /*** last line ? ***/
  136.         if (!bc)
  137.             break;
  138.  
  139.         /*** found name ? ***/
  140.         if (stricmp(&bc->bc_Name[0], n) == 0)
  141.             return(i);
  142.     }
  143.  
  144.     return(-1);
  145. }
  146.  
  147.  
  148.  
  149.  
  150. /*** find task in broker list ***/
  151.  
  152. LONG find_broker_task(ULONG t)
  153. {
  154.     struct BrokerCopy *bc;
  155.     LONG i;
  156.  
  157.     for (i=0; ; i++)
  158.     {
  159.         DoMethod(lv_broker, MUIM_List_GetEntry, i, &bc);
  160.  
  161.         /*** last line ? ***/
  162.         if (!bc)
  163.             break;
  164.  
  165.         /*** found task ? ***/
  166.         if (bc->bc_Task == t)
  167.             return(i);
  168.     }
  169.  
  170.     return(-1);
  171. }
  172.  
  173.  
  174.  
  175.  
  176. /*** disable gadgets & menus, show changes ***/
  177.  
  178. void check_broker(void)
  179. {
  180.     struct BrokerCopy *bc;
  181.  
  182.     BOOL disable_activate = TRUE, disable_deactivate = TRUE;
  183.     BOOL disable_interface = TRUE;
  184.  
  185.     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  186.  
  187.     if (bc->bc_Flags & COF_SHOW_HIDE)
  188.         disable_interface = FALSE;
  189.  
  190.     if (bc->bc_Flags & COF_ACTIVE)
  191.         disable_deactivate = FALSE;
  192.     else
  193.         disable_activate = FALSE;
  194.  
  195.  
  196.     /*** set status of gadgets ***/
  197.     set(bt_activate, MUIA_Disabled, disable_activate);
  198.     set(bt_deactivate, MUIA_Disabled, disable_deactivate);
  199.  
  200.     set(bt_show, MUIA_Disabled, disable_interface);
  201.     set(bt_hide, MUIA_Disabled, disable_interface);
  202.  
  203.  
  204.     /*** set status of menus ***/
  205.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_ACTIVATE, !disable_activate);
  206.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_DEACTIVATE, !disable_deactivate);
  207.  
  208.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_INTERFACE, !disable_interface);
  209. }
  210.  
  211.  
  212.  
  213.  
  214. /*** insert broker into listview ***/
  215.  
  216. BOOL insert_broker(void)
  217. {
  218.     static UBYTE count;
  219.  
  220.     struct List *l;
  221.     ULONG nr, i;
  222.     struct BrokerCopy *bc;
  223.  
  224.     if (l = AllocMem(sizeof(struct List), MEMF_PUBLIC))
  225.     {
  226.         struct Node *n, *nn;
  227.         LONG pos, curs;
  228.  
  229.         count++;
  230.  
  231.         /*** generate an empty list ***/
  232.         NewList(l);
  233.  
  234.         /*** private function to generate the system broker list ***/
  235.         nr = CopyBrokerList(l);
  236.  
  237.         get(lv_broker, MUIA_List_Active, &curs);
  238.  
  239.         /*** start at head of list ***/
  240.         n = l->lh_Head;
  241.         while (n && (nn = n->ln_Succ))
  242.         {
  243.             if ((pos = find_broker_name((char *)&((struct BrokerCopy *)n)->bc_Name[0])) >= 0)
  244.             {
  245.                 DoMethod(lv_broker, MUIM_List_GetEntry, pos, &bc);
  246.                 bc->bc_Flags = ((struct BrokerCopy *)n)->bc_Flags;
  247.                 bc->bc_Node.ln_Type = count;
  248.  
  249.                 if (curs == pos)
  250.                     check_broker();
  251.             }
  252.             else
  253.             {
  254.                 /*** insert broker ***/
  255.                 ((struct BrokerCopy *)n)->bc_Node.ln_Type = count;
  256.                 DoMethod(lv_broker, MUIM_List_Insert, &n, 1, MUIV_List_Insert_Sorted);
  257.             }
  258.  
  259.             /*** next node ***/
  260.             n = nn;
  261.         }
  262.  
  263.         /*** free list and allocated mem ***/
  264.         FreeBrokerList(l);
  265.         FreeMem(l, sizeof(struct List));
  266.  
  267.         for (i=0; ; i++)
  268.         {
  269.             DoMethod(lv_broker, MUIM_List_GetEntry, i, &bc);
  270.  
  271.             /*** last line ? ***/
  272.             if (!bc)
  273.                 break;
  274.  
  275.             /*** found old broker ? ***/
  276.             if (bc->bc_Node.ln_Type != count)
  277.                 DoMethod(lv_broker, MUIM_List_Remove, i--);
  278.         }
  279.     }
  280.  
  281.     return(TRUE);
  282. }
  283.  
  284.  
  285.  
  286.  
  287. /*** image-stuff ***/
  288.  
  289. /*
  290. DiskObject 'MUI-Exchange_sleep.info': $076bf6b4
  291. Size of DiskObjectStruct: 78  ImageStruct: 20
  292. GadgetRender: $07692038  Size: 560   Width: 54  Height: 35  Depth: 2
  293. */
  294.  
  295.  
  296. static UWORD mui_exchange_sleep_img1_data[] = {
  297.     0x0003,0x8000,0x0000,0x0000,0x0004,0x4000,0x0000,0x0000,
  298.     0x0008,0x4000,0x0000,0x0000,0x0018,0x4de0,0x0000,0x0000,
  299.     0x0020,0x3210,0x0000,0x0000,0x0020,0x0008,0x0000,0x0000,
  300.     0x0020,0x0008,0x0000,0x0000,0x0020,0xf008,0x0000,0x0000,
  301.     0x0020,0x2788,0x0000,0x0000,0x0010,0x4108,0x0000,0x0000,
  302.     0x0010,0xf208,0x0000,0x0000,0x0008,0x0790,0x0000,0x0000,
  303.     0x0008,0x0020,0x0000,0x0000,0x003c,0x00c0,0x0000,0x0400,
  304.     0x0046,0x3f00,0x0000,0x0c00,0x0083,0xe008,0x0000,0x0c00,
  305.     0x0100,0x8038,0x0000,0x0c00,0x0101,0x00fc,0x0000,0x0c00,
  306.     0x0386,0x03fc,0x0000,0x0c00,0x04c8,0x0ff0,0x0000,0x0c00,
  307.     0x08b0,0x3ffc,0xc180,0x2c00,0x0500,0xffc0,0x6300,0x4c00,
  308.     0x0203,0xfd80,0x363c,0x8c00,0x000f,0xf180,0x1c41,0x0c00,
  309.     0x003f,0xc180,0x1c42,0x0c00,0x00ff,0x0180,0x3640,0x0c00,
  310.     0x03fc,0x00c0,0x6340,0x0c00,0x03f0,0x003c,0xc180,0x0c00,
  311.     0x01c0,0x0000,0x0080,0x0c00,0x0102,0x0000,0x0100,0x0c00,
  312.     0x0001,0x0000,0x0600,0x0c00,0x0000,0x9fff,0xf800,0x0c00,
  313.     0x0000,0x6000,0x0000,0x0c00,0x0000,0x2000,0x0000,0x0c00,
  314.     0x7fff,0xffff,0xffff,0xfc00,0x0003,0x8000,0x0000,0x0000,
  315.     0x0007,0xc000,0x0000,0x0000,0x000f,0xc000,0x0000,0x0000,
  316.     0x001f,0xcde0,0x0000,0x0000,0x003f,0xfff0,0x0000,0x0000,
  317.     0x003f,0xfff8,0x0000,0x0000,0x003f,0xfff8,0x0000,0x0000,
  318.     0x003f,0x0ff8,0x0000,0x0000,0x003f,0xd878,0x0000,0x0000,
  319.     0x001f,0xbef8,0x0000,0x0000,0x001f,0x0df8,0x0000,0x0000,
  320.     0x000f,0xf870,0x0000,0x0000,0x000f,0xffe0,0x0000,0x0000,
  321.     0xffff,0xffff,0xffff,0xf800,0xd57f,0xff51,0x5552,0x5000,
  322.     0xd5ff,0xf55f,0x8003,0x5000,0xd5ff,0xd527,0xbfff,0x9000,
  323.     0xd5ff,0x5482,0x7fff,0xd000,0xd7ff,0x5205,0xffff,0xe000,
  324.     0xd7fd,0x4813,0xffff,0xf000,0xdff5,0x2043,0x3e7f,0xd000,
  325.     0xd754,0x813f,0x9cff,0x9000,0xd752,0x047f,0xc9c3,0x5000,
  326.     0xd548,0x107e,0x2392,0x5000,0xd520,0x607e,0x2391,0x5000,
  327.     0xd481,0x3e7f,0xc995,0x5000,0xd204,0xff3f,0x9c95,0x5000,
  328.     0xc413,0xffc3,0x3e55,0x5000,0xde47,0xffff,0xff55,0x5000,
  329.     0xbf11,0xffff,0xfe55,0x5000,0xd854,0xffff,0xf955,0x5000,
  330.     0xc555,0x6000,0x0555,0x5000,0xd555,0x1555,0x5555,0x5000,
  331.     0xd555,0x5555,0x5555,0x5000,0x8000,0x0000,0x0000,0x0000,
  332.  
  333. };
  334.  
  335. static struct Image mui_exchange_sleep_img1 = {
  336.     0x0000,0x0000,0x0036,0x0023,0x0002,
  337.     &mui_exchange_sleep_img1_data[0],
  338.     0x03,0x00,0x00000000,
  339. };
  340.  
  341. static struct DiskObject mui_exchange_sleep_dobj = {
  342.     0xe310,0x0001,
  343.     0x00000000,
  344.     0x00db,0x0050,0x0036,0x0024,0x0004,0x0003,0x0001,
  345.     (APTR)&mui_exchange_sleep_img1,NULL,
  346.     0x00000000,0x00000000,0x00000000,
  347.     0x0000,
  348.     0x00000000,
  349.     0x0003,
  350.     0x00000000,0x00000000,0x80000000,0x80000000,
  351.     0x00000000,0x00000000,0x00000000,
  352. };
  353.  
  354.  
  355.  
  356.  
  357. /*** mui-stuff ***/
  358.  
  359. /*** list hooks ***/
  360.  
  361. SAVEDS ASM struct BrokerCopy *broker_list_confunc(
  362.     REG(a0) struct Hook *hook,
  363.     REG(a2) APTR mem_pool,
  364.     REG(a1) struct BrokerCopy *b)
  365. {
  366.     struct BrokerCopy *bc;
  367.  
  368.     if (bc = AllocMem(sizeof(struct BrokerCopy), MEMF_ANY))
  369.     {
  370.         int i;
  371.         UBYTE *s, *d;
  372.  
  373.         s = (BYTE *)b;
  374.         d = (BYTE *)bc;
  375.  
  376.         for (i=0; i < sizeof(struct BrokerCopy); i++)
  377.             *d++ = *s++;
  378.  
  379.         return(bc);
  380.     }
  381.  
  382.     /*** insert nothing ***/
  383.     return(0);
  384. }
  385.  
  386. static struct Hook broker_list_conhook = {
  387.     {NULL, NULL},
  388.     (void *)broker_list_confunc,
  389.     NULL, NULL
  390. };
  391.  
  392.  
  393. SAVEDS ASM LONG broker_list_desfunc(
  394.     REG(a0) struct Hook *hook,
  395.     REG(a2) APTR mem_pool,
  396.     REG(a1) struct BrokerCopy *bc)
  397. {
  398.     FreeMem(bc, sizeof(struct BrokerCopy));
  399.     return(0);
  400. }
  401.  
  402. static struct Hook broker_list_deshook = {
  403.     {NULL, NULL},
  404.     (void *)broker_list_desfunc,
  405.     NULL, NULL
  406. };
  407.  
  408.  
  409. SAVEDS ASM LONG broker_list_dspfunc(
  410.     REG(a0) struct Hook *hook,
  411.     REG(a2) char **array,
  412.     REG(a1) struct BrokerCopy *bc)
  413. {
  414.     *array = bc->bc_Name;
  415.     return(0);
  416. }
  417.  
  418. static struct Hook broker_list_dsphook = {
  419.     {NULL, NULL},
  420.     (void *)broker_list_dspfunc,
  421.     NULL, NULL
  422. };
  423.  
  424.  
  425. SAVEDS ASM LONG broker_list_cmpfunc(
  426.     REG(a0) struct Hook *hook,
  427.     REG(a2) struct BrokerCopy *bc1,
  428.     REG(a1) struct BrokerCopy *bc2)
  429. {
  430.     return(stricmp(bc2->bc_Name, bc1->bc_Name));
  431. }
  432.  
  433. static struct Hook broker_list_cmphook = {
  434.     {NULL, NULL},
  435.     (void *)broker_list_cmpfunc,
  436.     NULL, NULL
  437. };
  438.  
  439.  
  440.  
  441. /*** broker hook ***/
  442.  
  443. SAVEDS ASM LONG broker_list_brkfunc(
  444.     REG(a0) struct Hook *hook,
  445.     REG(a2) Object obj,
  446.     REG(a1) CxMsg *cm)
  447. {
  448.     if ((CxMsgType(cm) == CXM_COMMAND) && (CxMsgID(cm) == CXCMD_LIST_CHG))
  449.         insert_broker();
  450.  
  451.     return(0);
  452. }
  453.  
  454. static struct Hook broker_list_brkhook = {
  455.     {NULL, NULL},
  456.     (void *)broker_list_brkfunc,
  457.     NULL, NULL
  458. };
  459.  
  460.  
  461.  
  462.  
  463. /*** arexx hooks ***/
  464.  
  465. SAVEDS ASM LONG select_name_rxfunc(
  466.     REG(a0) struct Hook *hook,
  467.     REG(a2) Object *appl,
  468.     REG(a1) ULONG *arg)
  469. {
  470.     char *name;
  471.  
  472.     /*** name valid ? ***/
  473.     if (name = (char *)*arg)
  474.     {
  475.         ULONG pos;
  476.  
  477.         if (pos = find_broker_name(name))
  478.         {
  479.             /*** set cursor & listview ***/
  480.             set(lv_broker, MUIA_List_Active, pos);
  481.             DoMethod(lv_broker, MUIM_List_Jump, pos);
  482.  
  483.             return(RETURN_OK);
  484.         }
  485.     }
  486.  
  487.     return(RETURN_ERROR);
  488. }
  489.  
  490. static const struct Hook select_name_rxhook = {
  491.     {NULL, NULL},
  492.     (void *)select_name_rxfunc,
  493.     NULL,NULL
  494. };
  495.  
  496.  
  497. SAVEDS ASM LONG select_task_rxfunc(
  498.     REG(a0) struct Hook *hook,
  499.     REG(a2) Object *appl,
  500.     REG(a1) ULONG *arg)
  501. {
  502.     ULONG task;
  503.  
  504.     /*** task valid ? ***/
  505.     if (task = *((ULONG *)*arg))
  506.     {
  507.         ULONG pos;
  508.  
  509.         if (pos = find_broker_task(task))
  510.         {
  511.             /*** set cursor & listview ***/
  512.             set(lv_broker, MUIA_List_Active, pos);
  513.             DoMethod(lv_broker, MUIM_List_Jump, pos);
  514.  
  515.             return(RETURN_OK);
  516.         }
  517.     }
  518.  
  519.     return(RETURN_ERROR);
  520. }
  521.  
  522. static const struct Hook select_task_rxhook = {
  523.     {NULL, NULL},
  524.     (void *)select_task_rxfunc,
  525.     NULL,NULL
  526. };
  527.  
  528.  
  529.  
  530.  
  531. /*** arexx list ***/
  532.  
  533. static struct MUI_Command arexx_list[] =
  534. {
  535.     {"select_name",        "NAME/A",            1,                &select_name_rxhook},
  536.     {"select_task",        "TASKADR/N/A",        1,                &select_task_rxhook},
  537.  
  538.     {"activate",        MC_TEMPLATE_ID,        ID_ACTIVATE,    NULL},
  539.     {"deactivate",        MC_TEMPLATE_ID,        ID_DEACTIVATE,    NULL},
  540.     {"remove",            MC_TEMPLATE_ID,        ID_REMOVE,        NULL},
  541.  
  542.     {"interface_show",    MC_TEMPLATE_ID,        ID_SHOW,        NULL},
  543.     {"interface_hide",    MC_TEMPLATE_ID,        ID_HIDE,        NULL},
  544.  
  545.     {NULL,                NULL,                0,                NULL}
  546. };
  547.  
  548.  
  549.  
  550.  
  551. /*** menu ***/
  552.  
  553. static const struct NewMenu menu_list[] =
  554. {
  555.     { NM_TITLE,    "Project",            0,    0,    0,    0                            },
  556.  
  557.     { NM_ITEM,    "About...",            "?",0,    0,    (APTR) ID_ABOUT                },
  558.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  559.     { NM_ITEM,    "Quit",                "Q",0,    0,    (APTR) ID_QUIT                },
  560.  
  561.  
  562.     { NM_TITLE,    "Broker",            0,    0,    0,    0                            },
  563.  
  564.     { NM_ITEM,    "Info",                "I",0,    0,    (APTR) ID_INFO                },
  565.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  566.     { NM_ITEM,    "Activate",            "A",0,    0,    (APTR) ID_ACTIVATE            },
  567.     { NM_ITEM,    "Deactivate",        "D",0,    0,    (APTR) ID_DEACTIVATE        },
  568.     { NM_ITEM,    "Remove",            "R",0,    0,    (APTR) ID_REMOVE            },
  569.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  570.     { NM_ITEM,    "Interface",        0,    0,    0,    (APTR) ID_INTERFACE            },
  571.     { NM_SUB,    "Show",                "S",0,    0,    (APTR) ID_SHOW                },
  572.     { NM_SUB,    "Hide",                "H",0,    0,    (APTR) ID_HIDE                },
  573.  
  574.     { NM_END,    NULL,                0,    0,    0,    0                            },
  575. };
  576.  
  577.  
  578.  
  579.  
  580. int main(int argc,char *argv[])
  581. {
  582.     /*** variables ***/
  583.     ULONG timer_sig = 0;
  584.  
  585.     /*** init ***/
  586.     BOOL not_end = TRUE;
  587.  
  588.     init();
  589.     if (CxBase = OpenLibrary("commodities.library", 0))
  590.     {
  591.  
  592.         /*** create mui-application ***/
  593.         app = ApplicationObject,
  594.             MUIA_Application_Title,                "MUI-Exchange",
  595.             MUIA_Application_Version,            "$VER: MUI-Exchange 0.8 (13.8.93)",
  596.             MUIA_Application_Copyright,            "© 1993 by kMel, Klaus Melchior",
  597.             MUIA_Application_Author,            "Klaus Melchior",
  598.             MUIA_Application_Description,        "Manages the system commodities list",
  599.             MUIA_Application_Base,                "MUIEXCH",
  600.             MUIA_Application_Menu,                menu_list,
  601.             MUIA_Application_Commands,            arexx_list,
  602.             MUIA_Application_BrokerHook,        &broker_list_brkhook,
  603.             MUIA_Application_SingleTask,        TRUE,
  604.             MUIA_Application_DiskObject,        &mui_exchange_sleep_dobj,
  605.  
  606.             SubWindow, wi_main = WindowObject,
  607.                 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  608.                 MUIA_Window_Title, "MUI-Exchange",
  609.                 WindowContents, VGroup,
  610.                     Child, VGroup,
  611.                         Child, HGroup,
  612.                             GroupSpacing(0),
  613.                             Child, bt_info        = KeyButton("Info",'i'),
  614.                             End,
  615.                         Child, VGroup,
  616.                             GroupSpacing(0),
  617.                             Child, lv_broker = ListviewObject,
  618.                                 MUIA_Listview_DoubleClick, TRUE,
  619.                                 MUIA_Listview_List, ListObject,
  620.                                     InputListFrame,
  621.                                     MUIA_List_ConstructHook, &broker_list_conhook,
  622.                                     MUIA_List_DestructHook, &broker_list_deshook,
  623.                                     MUIA_List_CompareHook, &broker_list_cmphook,
  624.                                     MUIA_List_DisplayHook, &broker_list_dsphook,
  625.                                     End,
  626.                                 End,
  627.                             Child, HGroup,
  628.                                 GroupSpacing(0),
  629.                                 Child, bt_activate        = KeyButton("Activate",'a'),
  630.                                 Child, bt_deactivate    = KeyButton("Deactivate",'d'),
  631.                                 Child, bt_remove        = KeyButton("Remove",'r'),
  632.                                 End,
  633.                             End,
  634.                         Child, HGroup,
  635.                             GroupSpacing(0),
  636.                             Child, bt_show    = KeyButton("Show Interface",'s'),
  637.                             Child, bt_hide    = KeyButton("Hide Interface",'h'),
  638.                             End,
  639.                         End,
  640.                     End,
  641.                 End,
  642.             End;
  643.  
  644.  
  645.         /*** application failed ? ***/
  646.         if (!app)
  647.             fail(app, "Creating application failed !");
  648.  
  649.         /*** connections & cycle ***/
  650.  
  651.         DoMethod(wi_main,        MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_QUIT            );
  652.  
  653.         DoMethod(lv_broker,        MUIM_Notify,    MUIA_Listview_DoubleClick,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_INFO            );
  654.         DoMethod(lv_broker,        MUIM_Notify,    MUIA_Listview_SelectChange,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_LV_ACTIVE    );
  655.  
  656.         DoMethod(lv_broker, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  657.             app, 2,
  658.             MUIM_Application_ReturnID, ID_LV_ACTIVE);
  659.  
  660.         DoMethod(bt_info,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_INFO            );
  661.  
  662.         DoMethod(bt_activate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_ACTIVATE        );
  663.         DoMethod(bt_deactivate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_DEACTIVATE    );
  664.         DoMethod(bt_remove,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_REMOVE        );
  665.  
  666.         DoMethod(bt_hide,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_HIDE            );
  667.         DoMethod(bt_show,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_SHOW            );
  668.  
  669.  
  670.         DoMethod(wi_main,        MUIM_Window_SetCycleChain,
  671.             lv_broker,
  672.             bt_activate, bt_deactivate, bt_remove,
  673.             bt_hide, bt_show,
  674.             bt_info,
  675.             NULL);
  676.  
  677.  
  678.         /*** open window ***/
  679.         set(wi_main, MUIA_Window_Open,            TRUE);
  680.         set(wi_main, MUIA_Window_ActiveObject,    lv_broker);
  681.  
  682.  
  683.         /*** get brokerlist ***/
  684.         insert_broker();
  685.  
  686.         /*** first scan & activate first entry ***/
  687.         set(lv_broker, MUIA_List_Active, 0);
  688.  
  689.         /*** create timer_port to refresh broker_list ***/
  690.         {
  691.             struct timerequest *timer_io;
  692.             struct MsgPort *timer_port;
  693.             struct Message *timer_msg;
  694.             ULONG error;
  695.  
  696.             if (timer_port = CreatePort(0, 0))
  697.             {
  698.                 timer_sig = (1<<(timer_port->mp_SigBit));
  699.  
  700.                 if (timer_io = (struct timerequest *) CreateExtIO(timer_port, sizeof(struct timerequest)))
  701.                 {
  702.                     if (!(error = OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *) timer_io, 0)))
  703.                     {
  704.                         /*** refresh-cycle is 1 second ***/
  705.                         timer_io->tr_node.io_Command = TR_ADDREQUEST;
  706.                         timer_io->tr_time.tv_secs = 1;
  707.                         timer_io->tr_time.tv_micro = 0;
  708.  
  709.                         SendIO((struct IORequest *) timer_io);
  710.  
  711.                         /*** main-loop ***/
  712.                         while (not_end)
  713.                         {
  714.                             ULONG signal, ret_sig, id, ret;
  715.                             char *n;
  716.                             struct BrokerCopy *bc;
  717.  
  718.                             switch (id = DoMethod(app, MUIM_Application_Input, &signal))
  719.                             {
  720.                                 case ID_ABOUT:
  721.                                     MUI_Request(app, wi_main, 0, NULL, "OK",
  722.                                         eC ePW "MUI-Exchange\n\n"
  723.                                         ePB "Version 0.8 (13.8.93)\n"
  724.                                         "Copyright 1993 by kMel, Klaus Melchior.\n"
  725.                                         "\nThis is a MUI-Application.\n"
  726.                                         "MUI is copyrighted by Stefan Stuntz.",
  727.                                         TAG_END);
  728.                                 break;
  729.  
  730.                                 case MUIV_Application_ReturnID_Quit:
  731.                                 case ID_QUIT:
  732.                                     not_end = FALSE;
  733.                                 break;
  734.  
  735.  
  736.                                 case ID_INFO:
  737.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  738.  
  739.                                     MUI_Request(app, wi_main, 0, NULL, "OK",
  740.                                         eC ePW "%s\n\n"
  741.                                         ePB eN "%s\n"
  742.                                         "%s",
  743.                                         bc->bc_Name, bc->bc_Title, bc->bc_Descr,
  744.                                     TAG_END);
  745.                                 break;
  746.  
  747.                                 case ID_LV_ACTIVE:
  748.                                     check_broker();
  749.                                 break;
  750.  
  751.  
  752.                                 case ID_ACTIVATE:
  753.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  754.                                     BrokerCommand(n = bc->bc_Name, CXCMD_ENABLE);
  755.                                 break;
  756.  
  757.                                 case ID_DEACTIVATE:
  758.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  759.                                     BrokerCommand(n = bc->bc_Name, CXCMD_DISABLE);
  760.                                 break;
  761.  
  762.                                 case ID_REMOVE:
  763.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  764.                                     BrokerCommand(bc->bc_Name, CXCMD_KILL);
  765.                                 break;
  766.  
  767.                                 case ID_SHOW:
  768.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  769.                                     ret = BrokerCommand(bc->bc_Name, CXCMD_APPEAR);
  770.                                 break;
  771.  
  772.                                 case ID_HIDE:
  773.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  774.                                     ret = BrokerCommand(bc->bc_Name, CXCMD_DISAPPEAR);
  775.                                 break;
  776.  
  777.  
  778.                                 /*** default ***/
  779.  
  780.                                 default:
  781.                                     if (id)
  782.                                         printf("ID: %d = %08lx\n", id, id);
  783.                                 break;
  784.                             }
  785.  
  786.                             if (not_end && signal)
  787.                                 ret_sig = Wait(signal | timer_sig);
  788.  
  789.                             /*** timer signal ? ***/
  790.                             if (ret_sig & timer_sig)
  791.                             {
  792.                                 while (timer_msg = GetMsg(timer_port))
  793.                                     ;
  794.  
  795.                                 insert_broker();
  796.  
  797.                                 /*** refresh cycle is 1 second ***/
  798.                                 timer_io->tr_node.io_Command = TR_ADDREQUEST;
  799.                                 timer_io->tr_time.tv_secs = 1;
  800.                                 timer_io->tr_time.tv_micro = 0;
  801.  
  802.                                 SendIO((struct IORequest *) timer_io);
  803.                             }
  804.  
  805.                         }
  806.  
  807.                         /*** clean up & close timer.device ***/
  808.                         if (!(CheckIO((struct IORequest *)timer_io)))
  809.                             AbortIO((struct IORequest *)timer_io);
  810.                         WaitIO((struct IORequest *)timer_io);
  811.                         CloseDevice((struct IORequest *) timer_io);
  812.                     }
  813.  
  814.                     DeleteExtIO((struct IORequest *) timer_io);
  815.                 }
  816.  
  817.                 while (timer_msg = GetMsg(timer_port))
  818.                     ;
  819.                 DeletePort(timer_port);
  820.             }
  821.         }
  822.  
  823.         CloseLibrary(CxBase);
  824.     }
  825.     fail(app, NULL);
  826. }
  827.  
  828.